package org.fjsei.yewu.bpm;

import io.camunda.spring.client.annotation.JobWorker;
import io.camunda.spring.client.annotation.VariablesAsType;
import io.camunda.spring.client.exception.BpmnError;
//import io.camunda.zeebe.spring.client.annotation.CustomHeaders;
//import io.camunda.zeebe.spring.client.annotation.JobWorker;
//import io.camunda.zeebe.spring.client.annotation.VariablesAsType;
import lombok.extern.slf4j.Slf4j;
import md.specialEqp.Report;
import md.specialEqp.ReportRepository;
import org.fjsei.yewu.config.MinioConfig;
import org.fjsei.yewu.dto.RepLink;
import org.fjsei.yewu.resolver.Comngrql;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;


@Slf4j
@Component
public class PdfWorker extends Comngrql {
    @Autowired
    private UniversalService universalService;
    private final ReportRepository reports;
    private final MinioConfig osscfg;

    public PdfWorker(ReportRepository reports, MinioConfig osscfg) {
        this.reports = reports;
        this.osscfg = osscfg;
    }
    @JobWorker(type="pdf_generate_alldone", autoComplete=true)
    public void onPdf_generate_alldone(@VariablesAsType PdfProcessVariables variables) throws Exception {
        Report report = entityOf(variables.getRepId(), Report.class);   //或者其他的申请单实体 都 instance of FlowStat
        if(null==report)   throw new BpmnError("notFind", "没这待处理报告");
        RepLink repLink=report.getLink();
        if("ori".equals(variables.getPdfType()))
            repLink.setOri(osscfg.getBucketName() +"/" +variables.getOssId());
        else if("rep".equals(variables.getPdfType()))
            repLink.setRep(osscfg.getBucketName() +"/" +variables.getOssId());
        report.setLink(repLink);
        log.info("网页转为Pdf完成 {}", report.getId());
        reports.save(report);
    }
}
